# Mattise Library Makefile
# Copyright 2007 Matthew Iselin

# final binary location
FINALBIN:=mattise.a

# setup all the variables
include ../../mkinc/userland.include

# archive flags
ARFLAGS:=rc $(FINALBIN)

# assembler
AS_SRCS:=crt0.s

# source and objects, and final binary
HEADERS:=mmsg.h process.h portio.h
SRCS:=newio.c thread.c msgio.c syscalls.c portio.c gcc_compat.c
OBJS:=$(patsubst %.s,%.o,$(AS_SRCS)) $(patsubst %.c,%.o,$(SRCS))

# echo command location
ECHO:=echo

# dependiencies
DEPFILES:=$(patsubst %.c,%.d,$(SRCS))

# buld the full archive
all: $(FINALBIN)

# install: copy across to the right location and clean the source directory
install: $(FINALBIN)
	mkdir -p lib
	mkdir -p include
	cp $(FINALBIN) lib/$(FINALBIN)
	cp crt0.o lib/crt0.o
	cp syscalls.o lib/mattise_syscalls.o
	for i in $(HEADERS); do \
	cp $$i include/$$i; \
	done
	rm $(OBJS) $(DEPFILES) $(FINALBIN)

# clean up
clean:
	rm $(OBJS) $(DEPFILES) $(FINALBIN)

# link command
$(FINALBIN) : $(OBJS)
	$(AR) $(ARFLAGS) $(OBJS)
	$(RANLIB) $(FINALBIN)

# included files
-include $(DEPFILES)

# C++ source
%.o : %.c
	$(C) $(CFLAGS) -MMD -MP -MT "$*.d" -c $< -o $@

# assembly
%.o : %.s
	$(AS) $< -o $@
